package com.talkyun.openx.server.helper;

/**
 * URI parser utils
 * <p>
 * Created by kevin on 2015/1/9.
 */
public class UriParser {

    public static String getUriLastPart(String uri, int pos, int len) {
        // ex: /api/app/find:(0, 2) => app/find
        String[] parts = LineHelper.split(uri, "/", true);
        int pos2 = parts.length - pos - len;
        if (parts.length == 0 || pos2 < 0) {
            return null;
        }

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < len; i++) {
            if (i != 0) {
                sb.append("/");
            }
            sb.append(parts[pos2 + i]);
        }
        return sb.toString();
    }
}
